package com.tgy.back.tracking;

/**
 * @Author: tgy
 * @Date: 2020-11-18 10:44
 */
public class Queens02 {

    private int[] locs;

    private int queen;

    private int num;


    public int queens(int queen) {

        if (queen < 1) {

            return 0;
        }

        num = 0;
        this.queen = queen;
        locs = new int[queen];

        find(0);


        return num;
    }

    private  void find(int row) {

        if (row == queen) {

            num++;
            printQueen();
            return;
        }

        for (int i = 0; i < queen; i++) {

            if (isPlace(row, i)) {

                locs[row] = i;
                find(row + 1);
            }
        }

    }

    private boolean isPlace(int row,int col) {

        for (int i = 0; i < row; i++) {

            if (locs[i] == col) {

                return false;
            }

            if (Math.abs(col - locs[i]) == Math.abs(i - row)) {

                return false;
            }
        }

        return true;
    }

    private void printQueen() {

        for (int i = 0; i < queen; i++) {

            for (int j = 0; j < queen; j++) {



            }

        }

    }
}
